import { http } from '@/utils/http/axios';

export interface BasicResponseModel<T = any> {
  code: number;
  message: string;
  row: T;
}

export interface BasicPageParams {
  pageNumber: number;
  pageSize: number;
  total: number;
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return http.request({
    url: '/admin/account/info',
    method: 'get',
  });
}

/**
 * @description: 用户登录
 */
export function login(data) {
  return http.request(
    {
      url: '/login',
      method: 'POST',
      data,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params, uid) {
  return http.request(
    {
      url: `/user/u${uid}/changepw`,
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户登出
 */
export const logout = () => {
  return http.request({
    url: `/admin/account/logout`,
    method: 'POST',
  });
};

/**
 * @description: 更新密码
 */
export const updatePassword = (data = {}) => {
  return http.request({
    url: `/uc/user/updatePassword`,
    method: 'put',
    data,
  });
};

/**
 * @description: 查询用户列表
 */
export function pageUser(data) {
  return http.request({
    url: '/admin/sys/user/page',
    method: 'post',
    data,
  });
}

/**
 * @description: 查询用户列表
 */
export function listUser(data = {}) {
  return http.request({
    url: '/admin/sys/user/list',
    method: 'post',
    data,
  });
}

/**
 * @description: 用户状态修改
 */
export function changeUserStatus(data) {
  return http.request({
    url: '/uc/user/updateStatus',
    method: 'put',
    data,
  });
}

/**
 * @description: 新增用户
 */
export function addUser(data = {}) {
  return http.request({
    url: '/admin/sys/user/add',
    method: 'post',
    data,
  });
}

/**
 * @description: 修改用户
 */
export function updateUser(data = {}) {
  return http.request({
    url: '/admin/sys/user/update',
    method: 'post',
    data,
  });
}

/**
 * @description: 获取组织下拉树列表(新增组织和用户时)
 */
export function getUserOrgTree() {
  return http.request({
    url: '/bms/orgnization/getUserOrgTree',
  });
}

/**
 * @description: 删除用户
 */
export function delUser(idList) {
  return http.request({
    url: '/admin/sys/user/delete',
    method: 'post',
    data: idList,
  });
}

/**
 * @description: 查询用户详情
 */
export function getUser(data) {
  return http.request({
    url: '/admin/sys/user/info',
    method: 'post',
    data,
  });
}

/**
 * @description: 用户密码重置
 */
export function resetUserPwd(data) {
  return http.request({
    url: '/admin/sys/user/updatePassword',
    method: 'post',
    data,
  });
}

export function accountUpdate(data) {
  return http.request({
    url: '/admin/account/update',
    method: 'post',
    data,
  });
}

export function accountPassword(data) {
  return http.request({
    url: '/admin/account/password',
    method: 'post',
    data,
  });
}
